#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using ll = int64_t;

ll n,k,T,e;
std::vector<std::vector<ll>> map;
std::vector<ll> d,jc;
const ll M = 1e9+7;

void solve(){
    std::cin>>n>>k;
    map.clear();
    map.resize(n+1);
    d.clear();
    d.resize(n+1);
    for(ll i=1;i<=n-1;i++){
        ll u,v;
        std::cin>>u>>v;
        map[u].push_back(v);
        map[v].push_back(u);
        d[u]++;
        d[v]++;
    }
    std::cin>>e;
    ll maxd=1;
    for(ll i=1;i<=n-1;i++){
        maxd=std::max(maxd,d[i]);
    }
    jc.clear();
    jc.resize(maxd+1);
    jc[1]=1;
    for(ll i=2;i<=maxd;i++){
        jc[i]=jc[i-1]*i%M;
    }
    ll ans=1;
    for(ll i=1;i<=n-1;i++){
        ans=(ans+jc[d[i]-1])%M;
    }
    std::cout<<(ans*2)%M<<'\n';
}

int main(){
    std::cin>>T;
    while(T--){
        solve();
    }
}